
const mongoose = require('mongoose');
const _ = require('lodash');
var commentService = require('../service/comment.service');

module.exports={
    addComment:addComment,
    findByMerchantId:findByMerchantId,
    findByOrderId:findByOrderId
};

function addComment(req,res,next){
    var commentInfo = req.body;
    if(_.isEmpty(commentInfo)){
        res.json({result:false,errMsg:'commentInfo can not be empty!'});
    }else {
        commentService.addComment(commentInfo,function(err,data){
            if(err){
                res.json({result:false,errMsg:Error(err)});
            }else {
                res.json({result:true,data:data});
            }
        });
    }
}

function findByMerchantId(req,res,next){
    var merchantId = req.params.merchantId;
    commentService.findByMerchantId(merchantId,function(err,data){
        if(err){
            res.json({result:false,errMsg:Error(err)});
        }else {
            res.json({result: true, data: data});
        }
    });
}

function findByOrderId(req,res,next){
    var orderId = req.params.orderId;
    commentService.findByOrderId(orderId,function(err,data){
        if(err){
            res.json({result:false,errMsg:Error(err)});
        }else {
            res.json({result:true, data: data});
        }
    });
}
